APP = snake_game
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)

CC = gcc
LINKLIBS = -lpthread
CFLAGS = -Wall 

$(APP): $(OBJS)
	$(CC) $^ -o $@   $(LINKLIBS)
	@echo Target: $@

%.o: %.c
	$(CC) $< -c -o $@   $(CFLAGS)

include $(SRCS:.c=.d)
%.d: %.c
	set -e; rm -f $@;\
	$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed  "s,^\($*\)\.o[ :]+,\1.o $@: ," $@.$$$$ > $@; \
	rm -f $@.$$$$;

clean:
	-rm -f $(OBJS) $(SRCS:.c=.d)
	@echo 'Tmpfile cleaned'
	
.PHONY: clean
